In [1]:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import os
In [2]:
%matplotlib inline
In [9]:
repos_path = "/Users/nus/temporal-features-for-nonres-buildings-library/"
In [10]:
meta = pd.read_csv(os.path.join(repos_path,"data/raw/meta_open_withclassificationobjectives.csv"), index_col='uid', parse_dates=["datastart","dataend"], dayfirst=True)
In [11]:
meta.info()
In [12]:
sns.set_style("whitegrid")
Use: http://stanford.edu/~mwaskom/software/seaborn/examples/horizontal_barplot.html
In [18]:
meta.primaryspaceusage.value_counts()
Out[18]:
In [19]:
meta.usagecategory.value_counts()
Out[19]:
In [13]:
meta.info()#[['industry','timezone']].head()
In [14]:
meta.head()
Out[14]:
In [15]:
df = pd.pivot_table(meta.reset_index(), index='timezone', columns='subindustry', values='uid', aggfunc='count')
In [16]:
df
Out[16]:
In [17]:
# crashes = sns.load_dataset("car_crashes").sort_values("total", ascending=False)
location = pd.DataFrame(meta.timezone.value_counts()).reset_index()
location
Out[17]:
In [12]:
def createbarchart(df, column, ylabel, color, filelabel):
# Initialize the matplotlib figure
#sns.set_context('poster', font_scale=1)
location = pd.DataFrame(df[column].value_counts()).reset_index()
f, ax = plt.subplots(figsize=(9, 5))
sns.set_color_codes("pastel")
sns.barplot(x=column, y="index", data=location[:15], color=color)
# Add a legend and informative axis label
ax.legend(ncol=2, loc="lower right", frameon=True)
ax.set(ylabel=ylabel,
xlabel="Number of Buildings")
sns.despine(left=True, bottom=True)
plt.subplots_adjust(left=0.3)
plt.tight_layout()
plt.savefig(os.path.join(repos_path,"reports/figures/metadataoverview/"+filelabel+".png"))
In [13]:
location[:15]
Out[13]:
In [14]:
meta["string_starttime"] = meta.datastart.apply(lambda x: str(x.date()))
In [15]:
sns.set_context("paper", font_scale=2)
createbarchart(meta, "string_starttime", "Data Starting Time", "m","starttimesbar")
In [16]:
#sns.set_style("white")
createbarchart(meta, "timezone", "Time Zones", "b","timezonesbar")
In [17]:
createbarchart(meta, "industry", "Industry", "r", "bar_industry")
In [18]:
createbarchart(meta, "subindustry", "Sub-Industry", "g","bar_subindustry")
In [19]:
createbarchart(meta, "primaryspaceusage", "Primary Use", "y", "bar_primaryspaceuse")
In [20]:
import numpy as np
In [21]:
# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
# row and column sharing
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row')
ax1.plot(x, y)
ax1.set_title('Sharing x per column, y per row')
ax2.scatter(x, y)
ax3.scatter(x, 2 * y ** 2 - 1, color='r')
ax4.plot(x, 2 * y ** 2 - 1, color='r')
Out[21]:
In [22]:
sns.set_color_codes("pastel")
sns.set_context(font_scale=1)
In [23]:
import matplotlib.gridspec as gridspec
In [24]:
plt.figure(figsize=(18,10))
gs = gridspec.GridSpec(2, 8)
#f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2,2, figsize=(20, 9))#
# ax = plt.subplot2grid((2,2),(0, 0))
location = pd.DataFrame(meta["timezone"].value_counts()).reset_index()
ax1 = plt.subplot(gs[0,0:4])
ax1 = sns.barplot(x="timezone", y="index", data=location[:15], color="b")
ax1.legend(ncol=2, loc="lower right", frameon=True)
ax1.set(ylabel="Time Zones", xlabel="Number of Buildings")
location = pd.DataFrame(meta["industry"].value_counts()).reset_index()
ax2 = plt.subplot(gs[0,4:])
ax2 = sns.barplot(x="industry", y="index", data=location[:15], color="g")
ax2.legend(ncol=2, loc="lower right", frameon=True)
ax2.set(ylabel="Industry", xlabel="Number of Buildings")
location = pd.DataFrame(meta["subindustry"].value_counts()).reset_index()
ax3 = plt.subplot(gs[1,0:4])
ax3 = sns.barplot(x="subindustry", y="index", data=location[:15], color="r")
ax3.legend(ncol=2, loc="lower right", frameon=True)
ax3.set(ylabel="Sub-Industry", xlabel="Number of Buildings")
location = pd.DataFrame(meta["primaryspaceusage"].value_counts()).reset_index()
ax4 = plt.subplot(gs[1,4:])
ax4 = sns.barplot(x="primaryspaceusage", y="index", data=location[:15], color="y")
ax4.legend(ncol=2, loc="lower right", frameon=True)
ax4.set(ylabel="Primary Use", xlabel="Number of Buildings")
sns.despine(left=True, bottom=True)
plt.subplots_adjust(left=0.3)
plt.tight_layout()
plt.savefig(os.path.join(repos_path,"reports/figures/metadataoverview/allbars.pdf"))
In [ ]:
In [ ]: